package com.niuke;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 22. 查字典
 * https://blog.csdn.net/qq_34143141/article/details/131489097
 */
public class NiukeMoni22 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String prefix = scanner.next();
        int n = scanner.nextInt();
        String[] input = new String[n];
        for (int i = 0; i < n; i++) {
            input[i] = scanner.next();
        }

        List<String> result = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (input[i].startsWith(prefix)) {
                result.add(input[i]);
            }
        }

        for (int i = 0; i < result.size(); i++) {
            System.out.println(result.get(i));
        }
    }

}
